
<form id="form" class="layui-form" action="{:url()}" method="post">
    <input type="hidden" name="id" value="{$data['id']}">

    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" value="{$data['name']}" lay-verify="required" lay-vertype="tips" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">具体描述</label>
        <div class="layui-input-block" style="width: 50%;">
            <textarea name="remark" placeholder="请输入内容" class="layui-textarea">{$data['remark']}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择权限</label>
        <div class="layui-input-block">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div style="border-bottom: 1px solid #ccc;height: 40px;">
                            <input lay-filter="selectAll" type="checkbox" lay-skin="primary" title="全选">
                        </div>
                        {volist name="menuList" id="item"}
                            <div class="oneGroup" style="border-bottom: 1px solid #ccc;height: 100px;">
                                <div class="layui-col-md2 bindSelect">
                                    <input lay-filter="selectP" type="checkbox" name="ids[]" value="{$item['id']}" lay-skin="primary" title="{$item['name']}" {if $item['checked'] == 1}checked{/if} >
                                </div>
                                <div class="layui-col-md10">
                                    {notempty name="item['children']"}
                                        {volist name="item['children']" id="vo"}
                                            <input lay-filter="selectC" type="checkbox" name="ids[]" value="{$vo['id']}" lay-skin="primary" title="{$vo['name']}" {if $vo['checked'] == 1}checked{/if} >
                                        {/volist}
                                    {/notempty}
                                </div>
                            </div>
                        {/volist}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn submitForm" formId="form">提交</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(function(){
        var currentLayerIndex = parent.ybLayer.getFrameIndex(window.name);

        $('.submitForm').click(function (evt) {
            formPost(evt, $(this), function (res) {
                ybLayer.msg(res.msg,{icon: 6});
                setTimeout(function () {
                    parent.ybLayer.close(currentLayerIndex);
                    parent.ybTable.reload('mytable');
                }, 1000);
            }, function (res) {
                ybLayer.msg(res.msg, {icon: 5});
            });
            return false;
        });

        //全选
        ybForm.on('checkbox(selectAll)', function(that){
            var child = $('.oneGroup').find('input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = that.elem.checked;
            });
            ybForm.render('checkbox');
        });
        //单选父级
        ybForm.on('checkbox(selectP)', function(that){
            var child = $(this).parents('.oneGroup').find('input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = that.elem.checked;
            });
            ybForm.render('checkbox');
        });
        //单选个体,选中时上级跟着选中
        ybForm.on('checkbox(selectC)', function(that){
            if(that.elem.checked == true){
                var child = $(this).parents('.oneGroup').children('.bindSelect').find('input[type="checkbox"]');
                child.each(function(index, item){
                    item.checked = that.elem.checked;
                });
            }
            ybForm.render('checkbox');
        });

    })
</script>